package cn.bookshare.book.action;

import cn.bookshare.category.service.CategoryService;
import cn.bookshare.book.service.BookService;
import cn.bookshare.book.vo.Book;
import cn.bookshare.utils.PageBean;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
/**
 * 项目名称：BookShare 
 * @author 热血绅士
 * @version 创建时间：2017年4月23日 下午5:58:44  
 *
 * 类名称：BookAction 
 * 类说明:
 * 修改备注：
 *
 */
public class BookAction extends ActionSupport implements
		ModelDriven<Book> {
	// 用于接收数据的模型驱动.
	private Book book = new Book();
	// 注入商品的Service
	private BookService bookService;
	// 接收分类cid
	private Integer cid;
	// 接收二级分类id
	private Integer csid;

	public Integer getCsid() {
		return csid;
	}

	public void setCsid(Integer csid) {
		this.csid = csid;
	}

	// 注入一级分类的Service
	private CategoryService categoryService;
	// 接收当前页数:
	private int page;

	public void setPage(int page) {
		this.page = page;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public void setCid(Integer cid) {
		this.cid = cid;
	}

	public Integer getCid() {
		return cid;
	}

	public void setBookService(BookService bookService) {
		this.bookService = bookService;
	}

	public Book getModel() {
		return book;
	}

	// 根据商品的ID进行查询商品:执行方法:
	public String findByPid() {
		// 调用Service的方法完成查询.
		book = bookService.findByBid(book.getBid());
		return "findByPid";
	}

	// 根据分类的id查询商品:
	public String findByCid() {
		// List<Category> cList = categoryService.findAll();
		PageBean<Book> pageBean = bookService.findByPageCid(cid, page);// 根据一级分类查询商品,带分页查询
		// 将PageBean存入到值栈中:
		ActionContext.getContext().getValueStack().set("pageBean", pageBean);
		return "findByCid";
	}

	// 根据二级分类id查询商品:
	public String findByCsid() {
		// 根据二级分类查询商品
		PageBean<Book> pageBean = bookService.findByPageCsid(csid, page);
		// 将PageBean存入到值栈中:
		ActionContext.getContext().getValueStack().set("pageBean", pageBean);
		return "findByCsid";
	}
	
}
